const baseUrl = "http://localhost:3000";
function http({url,data,method='get'}){
	return new Promise((resolve,reject)=>{
		uni.request({
			url:baseUrl+url,
			data,
			method,
			success:(res)=>{
				resolve(res.data);
			},
			fail:(err)=>{
				reject(err);
			}
		})
	})
}

export default{
	//登录接口
	login(data){
		return http({
			url:'/users/login',
			data,
			method:'post',
		})
	},
	//第二次用缓存重新登录
	reLogin(data){
		return http({
			url:'/users/relogin',
			data,
		})
	},
	//退出登录
	logout(){
		return http({
			url:'/users/logout'
		})
	},
	//修改密码
	modifyPassword(data){
		return http({
			url:'/users/modifypwd',
			data,
			method:'post',
		})
	},
	
	//获取城市列表
	getCity(){
		return http({
			url:'/address/cities'
		})
	},
	//根据关键词呈现
	searchCity(keywords){
		return http({
			url:'/address/allcity',
			data:{
				keywords,
			}
		})
	},
	
	//添加收货地址
	add_address(username,addr_str){
		return http({
			url:'/address/add',
			method:'post',
			data:{
				addr_str,
				username
			}
		})
	}
}